//
//  DemonLord.m
//  TowerDefence
//
//  Created by K3 on 5/31/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DemonLord.h"
#import "PlayScreen.h"
#import "iCoreGUIController.h"

@implementation DemonLord

-(id)initDemonLordWith:(PlayScreen*)_playScreen withRoad:(NSMutableArray*)_road{
    self=[super initEnemyWith:_playScreen];
    armor=2;
    HP=500;
    speed=0.5f;
    road=_road;
    nextHeadingPoint=1;
    damage = 20;
    moneyOnDie = 30;
    
    spriteBody = [CCSprite spriteWithSpriteFrameName:@"Demon_Lord_Move_01.png"];
    [self drawBloodMeterWithLength:spriteBody.contentSize.width/2 + 10 width:3 position:ccp(spriteBody.contentSize.width/2, spriteBody.contentSize.height)];

    return self;
}

-(void)animationMoveLeft{
    //NSLog(@"Running");
    [super animationMoveLeft];
    NSMutableArray *anim=[self loadAnimationWithNumberOfFrames:12 withFrameName:@"Demon_Lord_Move"];
    CCAnimation *animation = [CCAnimation animationWithFrames:anim delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationMoveUp{
    [super animationMoveUp];
    NSMutableArray *anim=[self loadAnimationWithNumberOfFrames:12 withFrameName:@"Demon_Lord_Move"];
    CCAnimation *animation = [CCAnimation animationWithFrames:anim delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}
-(void)animationMoveDown{
    [super animationMoveDown];
    NSMutableArray *anim=[self loadAnimationWithNumberOfFrames:12 withFrameName:@"Demon_Lord_Move_Down"];
    CCAnimation *animation = [CCAnimation animationWithFrames:anim delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}
-(void)animationBattle{
    [super animationBattle];
    NSMutableArray *anim=[self loadAnimationWithNumberOfFrames:25 withFrameName:@"Demon_Lord_Attack"];
    CCAnimation *animation = [CCAnimation animationWithFrames:anim delay:0.1];
    
    CCCallFunc *playSound = [CCCallFunc actionWithTarget:self selector:@selector(playSoundAttack)];
    
//    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCSequence actions:playSound, [CCAnimate actionWithAnimation:animation], nil]]];
    CCCallFunc *func=[CCCallFunc actionWithTarget:self selector:@selector(battle)];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCSequence actions:[CCAnimate actionWithAnimation:animation],playSound,[CCDelayTime actionWithDuration:0.5],func, nil]]];
}

-(void)playSoundAttack {
    if(!handler.mainGUIController.isMuteSound) {
        [handler.mainGUIController playEffect:AUDIO_DEMON_LORD_ATTACK];
    }
}

-(void)animationDie{
    [super animationDie];
    NSMutableArray *anim=[self loadAnimationWithNumberOfFrames:9 withFrameName:@"Demon_Lord_Die"];
    CCAnimation *animation = [CCAnimation animationWithFrames:anim delay:0.1];
    CCCallFunc *dieCallBack = [CCCallFunc actionWithTarget:self selector:@selector(dieCallBack)];
    [spriteBody runAction:[CCSequence actions:[CCAnimate actionWithAnimation:animation],dieCallBack, nil]];
}

@end
